<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/doctrine/BaseFormFilterDoctrine.class.php');

/**
 * DadosUsuario filter form base class.
 *
 * @package    filters
 * @subpackage DadosUsuario *
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 11675 2008-09-19 15:21:38Z fabien $
 */
class BaseDadosUsuarioFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id_usuario'          => new sfWidgetFormDoctrineChoice(array('model' => 'sfGuardUser', 'add_empty' => true)),
      'id_usuario_pai'      => new sfWidgetFormDoctrineChoice(array('model' => 'DadosUsuario', 'add_empty' => true)),
      'tp_usuario'          => new sfWidgetFormFilterInput(),
      'no_usuario'          => new sfWidgetFormFilterInput(),
      'nu_cpf'              => new sfWidgetFormFilterInput(),
      'nu_cpf_pai'          => new sfWidgetFormFilterInput(),
      'nu_cpf_mae'          => new sfWidgetFormFilterInput(),
      'no_usuario_pai'      => new sfWidgetFormFilterInput(),
      'no_usuario_mae'      => new sfWidgetFormFilterInput(),
      'sobrenome'           => new sfWidgetFormFilterInput(),
      'email'               => new sfWidgetFormFilterInput(),
      'nu_ddd_tel'          => new sfWidgetFormFilterInput(),
      'nu_tel'              => new sfWidgetFormFilterInput(),
      'st_estado_civil'     => new sfWidgetFormFilterInput(),
      'nu_renda'            => new sfWidgetFormFilterInput(),
      'nu_tempo_residencia' => new sfWidgetFormFilterInput(),
      'ds_profissao'        => new sfWidgetFormFilterInput(),
      'sexo'                => new sfWidgetFormFilterInput(),
      'dt_nascimento'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'groups_list'         => new sfWidgetFormDoctrineChoiceMany(array('model' => 'sfGuardGroup')),
      'permissions_list'    => new sfWidgetFormDoctrineChoiceMany(array('model' => 'sfGuardPermission')),
    ));

    $this->setValidators(array(
      'id_usuario'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => 'sfGuardUser', 'column' => 'id')),
      'id_usuario_pai'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => 'DadosUsuario', 'column' => 'id_dados_usuario')),
      'tp_usuario'          => new sfValidatorPass(array('required' => false)),
      'no_usuario'          => new sfValidatorPass(array('required' => false)),
      'nu_cpf'              => new sfValidatorPass(array('required' => false)),
      'nu_cpf_pai'          => new sfValidatorPass(array('required' => false)),
      'nu_cpf_mae'          => new sfValidatorPass(array('required' => false)),
      'no_usuario_pai'      => new sfValidatorPass(array('required' => false)),
      'no_usuario_mae'      => new sfValidatorPass(array('required' => false)),
      'sobrenome'           => new sfValidatorPass(array('required' => false)),
      'email'               => new sfValidatorPass(array('required' => false)),
      'nu_ddd_tel'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'nu_tel'              => new sfValidatorPass(array('required' => false)),
      'st_estado_civil'     => new sfValidatorPass(array('required' => false)),
      'nu_renda'            => new sfValidatorPass(array('required' => false)),
      'nu_tempo_residencia' => new sfValidatorPass(array('required' => false)),
      'ds_profissao'        => new sfValidatorPass(array('required' => false)),
      'sexo'                => new sfValidatorPass(array('required' => false)),
      'dt_nascimento'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'groups_list'         => new sfValidatorDoctrineChoiceMany(array('model' => 'sfGuardGroup', 'required' => false)),
      'permissions_list'    => new sfValidatorDoctrineChoiceMany(array('model' => 'sfGuardPermission', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('dados_usuario_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addGroupsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.sfGuardUserGroup sfGuardUserGroup')
          ->andWhereIn('sfGuardUserGroup.group_id', $values);
  }

  public function addPermissionsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.sfGuardUserPermission sfGuardUserPermission')
          ->andWhereIn('sfGuardUserPermission.permission_id', $values);
  }

  public function getModelName()
  {
    return 'DadosUsuario';
  }

  public function getFields()
  {
    return array(
      'id_dados_usuario'    => 'Number',
      'id_usuario'          => 'ForeignKey',
      'id_usuario_pai'      => 'ForeignKey',
      'tp_usuario'          => 'Text',
      'no_usuario'          => 'Text',
      'nu_cpf'              => 'Text',
      'nu_cpf_pai'          => 'Text',
      'nu_cpf_mae'          => 'Text',
      'no_usuario_pai'      => 'Text',
      'no_usuario_mae'      => 'Text',
      'sobrenome'           => 'Text',
      'email'               => 'Text',
      'nu_ddd_tel'          => 'Number',
      'nu_tel'              => 'Text',
      'st_estado_civil'     => 'Text',
      'nu_renda'            => 'Text',
      'nu_tempo_residencia' => 'Text',
      'ds_profissao'        => 'Text',
      'sexo'                => 'Text',
      'dt_nascimento'       => 'Date',
      'groups_list'         => 'ManyKey',
      'permissions_list'    => 'ManyKey',
    );
  }
}